<?php

require_once 'Pipes/Exception.php';
require_once 'Pipes/FileSystem/File.php';

class Pipes_FileSystem_File_Finder
{
    public function find($name)
    {
        $paths = explode(PATH_SEPARATOR, get_include_path());
        
        foreach ($paths as $path) {
            $path = rtrim($path, '/');
            $file = new Pipes_FileSystem_File($path . '/' . $name);
            if ($file->exists()) {
                return $file;
            }
        }
        
        throw new Pipes_Exception("unable to locate [{$name}]");
    }
    
    public function findByClass($name)
    {
        return $this->find(str_replace('_', '/', $name) . '.php');
    }

    public function requireByClass($name) {
        $file = $this->find(str_replace('_', '/', $name) . '.php');
        $file->requireOnce();
    }
}
